home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / utils / graphic / viewers / jpeg / msdos / dvpeg / src1b / jrevdct.asm < prev    next >
Encoding:
Assembly Source File  |  1992-06-09  |  7.0 KB  |  385 lines

  1.     .286p
  2.     ifndef    ??version
  3. publicdll macro    name
  4.     public    name
  5.     endm
  6. $comm    macro    name,dist,size,count
  7.     comm    dist name:BYTE:count*size
  8.     endm
  9.     else
  10. $comm    macro    name,dist,size,count
  11.     comm    dist name[size]:BYTE:count
  12.     endm
  13.     endif
  14. _TEXT    segment byte public 'CODE'
  15. _TEXT    ends
  16. DGROUP    group    _DATA,_BSS
  17.     assume    cs:_TEXT,ds:DGROUP
  18. _DATA    segment word public 'DATA'
  19. d@    label    byte
  20. d@w    label    word
  21. _DATA    ends
  22. _BSS    segment word public 'BSS'
  23. b@    label    byte
  24. b@w    label    word
  25. _BSS    ends
  26. _TEXT    segment byte public 'CODE'
  27.     ;
  28.     ;    GLOBAL void
  29.     ;
  30.     assume    cs:_TEXT
  31. _j_rev_dct    proc    near
  32.     push    bp
  33.     mov    bp,sp
  34.     sub    sp,236
  35.     push    si
  36.     push    di
  37.     ;
  38.     ;    j_rev_dct (DCTBLOCK data)
  39.     ;    {
  40.     ;      int pass, rowctr;
  41.     ;      register DCTELEM *inptr, *outptr;
  42.    ;      DCTBLOCK workspace;
  43.    ;    
  44.    ;      /* Each iteration of the inner loop performs one 8-point 1-D IDCT.
  45.    ;       * It reads from a *row* of the input matrix and stores into a *column*
  46.     ;       * of the output matrix.  In the first pass, we read from the data[] array
  47.    ;       * and store into the local workspace[].  In the second pass, we read from
  48.     ;       * the workspace[] array and store into data[], thus performing the
  49.    ;       * equivalent of a columnar IDCT pass with no variable array indexing.
  50.    ;       */
  51.    ;    
  52.    ;    
  53.     mov    si,word ptr [bp+4]
  54.    ;    
  55.    ;      inptr = data;            /* initialize pointers for first pass */
  56.    ;    
  57.     lea    ax,word ptr [bp-236]
  58.     mov    di,ax
  59.    ;    
  60.    ;      outptr = workspace;
  61.    ;    
  62.     mov    word ptr [bp-2],1
  63.     jmp    @1@194
  64. @1@50:
  65.    ;    
  66.     ;      for (pass = 1; pass >= 0; pass--) {
  67.    ;    
  68.     mov    word ptr [bp-4],7
  69.     jmp    @1@122
  70. @1@74:
  71.    ;    
  72.    ;        for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  73.    ;          /* many tmps have nonoverlapping lifetime -- flashy register colourers
  74.     ;           * should be able to do this lot very well
  75.    ;           */
  76.     ;          INT32 in0, in1, in2, in3, in4, in5, in6, in7;
  77.     ;          INT32 tmp10, tmp11, tmp12, tmp13;
  78.     ;          INT32 tmp20, tmp21, tmp22, tmp23;
  79.     ;          INT32 tmp30, tmp31;
  80.     ;          INT32 tmp40, tmp41, tmp42, tmp43;
  81.     ;          INT32 tmp50, tmp51, tmp52, tmp53;
  82.     ;          SHIFT_TEMPS
  83.     ;
  84.     ;
  85.     .386
  86.     movsx eax, word ptr [si+4]
  87.     mov    [bp-16], eax
  88.     ;
  89.     ;            in2 = inptr[2];
  90.     ;
  91.     movsx ebx, word ptr [si+8]
  92.     mov    [bp-24], ebx
  93.     ;
  94.     ;            in4 = inptr[4];
  95.     ;
  96.     movsx edx, word ptr [si+10]
  97.     mov    [bp-28], edx
  98.     ;
  99.     ;            in5 = inptr[5];
  100.     ;
  101.     movsx ecx, word ptr [si+12]
  102.     mov    [bp-32], ecx
  103.     ;
  104.     ;            in6 = inptr[6];
  105.     ;
  106.     movsx ecx, word ptr [si]
  107.     mov    [bp-8], ecx
  108.     ;
  109.     ;            in0 = inptr[0];
  110.     ;
  111.     ;            /* These values are scaled by DCT_SCALE */
  112.     ;
  113.     ;
  114.     add    ecx, ebx
  115.     imul    ecx, 46341
  116.     mov    [bp-40], ecx
  117.     ;
  118.     ;            tmp10 = (in0 + in4) * COS_1_4;
  119.     ;
  120.     mov    edx, [bp-32]
  121.     imul    edx, 25080
  122.     mov    ebx, [bp-16]
  123.     imul    ebx, 60547
  124.     add    edx, ebx
  125.     mov    [bp-52], edx
  126.     ;
  127.     ;            tmp13 = in6 * SIN_1_8 + in2 * COS_1_8;
  128.     ;
  129.     add    edx, ecx
  130.     mov    [bp-56], edx
  131.     ;
  132.     ;            tmp20 = tmp10 + tmp13;
  133.     ;
  134.     sub    ecx, [bp-52]
  135.     mov    [bp-68], ecx
  136.     ;
  137.     ;            tmp23 = tmp10 - tmp13;
  138.     ;
  139.     ;
  140.     mov    ecx, [bp-8]
  141.     sub    ecx, [bp-24]
  142.     imul    ecx, 46341
  143.     mov    [bp-44], ecx
  144.     ;
  145.     ;            tmp11 = (in0 - in4) * COS_1_4;
  146.     ;
  147.     mov    ecx, [bp-16]
  148.     imul    ecx, 25080
  149.     mov    ebx,[bp-32]
  150.     imul    ebx, 060547
  151.     sub    ecx, ebx
  152.     mov    [bp-48], ecx
  153.     ;
  154.     ;            tmp12 = in2 * SIN_1_8 - in6 * COS_1_8;
  155.     ;
  156.     add    ecx, [bp-44]
  157.     mov    [bp-60], ecx
  158.     ;
  159.     ;            tmp21 = tmp11 + tmp12;
  160.     ;
  161.     mov    ebx, [bp-44]
  162.     sub    ebx, [bp-48]
  163.     mov    [bp-64], ebx
  164.     ;
  165.     ;            tmp22 = tmp11 - tmp12;
  166.     ;
  167.     ;
  168.     ;            /* These values are scaled by OVERSCALE */
  169.     ;
  170.     ;
  171.     movsx    eax, word ptr [si+6]
  172.     mov    [bp-20], eax
  173.     ;
  174.     ;            in3 = inptr[3];
  175.     ;
  176.     add    eax, [bp-28]
  177.     imul    eax, 46341
  178.     add    eax, 8192
  179.     sar    eax, 14
  180.     mov    [bp-72], eax
  181.     ;
  182.     ;            tmp30 = UNFIXO((in3 + in5) * COS_1_4);
  183.     ;
  184.     mov ecx, [bp-20]
  185.     sub ecx, [bp-28]
  186.     imul ecx, 46341
  187.     add ecx, 8192
  188.     sar ecx, 14
  189.     mov [bp-76], ecx
  190.     ;
  191.     ;            tmp31 = UNFIXO((in3 - in5) * COS_1_4);
  192.     ;
  193.     ;
  194.     movsx    ebx, word ptr [si+2]
  195.     sal    ebx, 2
  196.     mov    [bp-12], ebx
  197.     ;
  198.     ;            in1 = inptr[1];
  199.     ;            OVERSHIFT(in1);
  200.     ;
  201.     movsx    edx, word ptr [si+14]
  202.     sal    edx, 2
  203.     mov    [bp-36], edx
  204.     ;
  205.     ;            in7 = inptr[7];
  206.     ;            OVERSHIFT(in7);
  207.     ;
  208.     ;
  209.     add    ecx, edx
  210.     mov    [bp-84], ecx
  211.     ;
  212.     ;            tmp41 = in7 + tmp31;
  213.     ;
  214.     sub    edx, [bp-76]
  215.     mov    [bp-92], edx
  216.     ;
  217.     ;            tmp43 = in7 - tmp31;
  218.     ;
  219.     mov    edx, [bp-12]
  220.     add    edx, eax
  221.     mov    [bp-80], edx
  222.     ;
  223.     ;            tmp40 = in1 + tmp30;
  224.     ;
  225.     mov    ebx, [bp-12]
  226.     sub    ebx, eax
  227.     mov    [bp-88], ebx
  228.     ;
  229.     ;            tmp42 = in1 - tmp30;
  230.     ;
  231.     ;            /* And these are scaled by DCT_SCALE */
  232.     ;
  233.     ;
  234.     imul    edx, 3196
  235.     imul    ecx, 16069
  236.     sub    edx, ecx
  237.     mov    [bp-100], edx
  238.     ;
  239.     ;            tmp51 = tmp40 * OSIN_1_16 - tmp41 * OCOS_1_16;
  240.     ;
  241.     ;
  242.     add    edx, [bp-68]
  243.     add    edx, 65536    ; do round up on upper word
  244.     sar    edx, 17
  245.     mov    [di+48], dx
  246.     ;
  247.     ;            outptr[DCTSIZE*3] = (DCTELEM) UNFIXH(tmp23 + tmp51);
  248.     ;
  249.     mov    edx, [bp-68]
  250.     sub    edx, [bp-100]
  251.     add    edx, 65536
  252.     sar    edx, 17
  253.     mov    [di+64], dx
  254.     ;
  255.     ;            outptr[DCTSIZE*4] = (DCTELEM) UNFIXH(tmp23 - tmp51);
  256.     ;
  257.     ;
  258.     mov    ecx, [bp-84]
  259.     imul    ecx, 3196
  260.     mov    edx, [bp-80]
  261.     imul    edx, 16069
  262.     add    edx, ecx
  263.     mov    [bp-96], edx
  264.     ;
  265.     ;            tmp50 = tmp40 * OCOS_1_16 + tmp41 * OSIN_1_16;
  266.     ;
  267.     mov    edx, [bp-56]
  268.     add    edx, [bp-96]
  269.     add    edx, 65536
  270.     sar    edx, 17
  271.     mov    [di], dx
  272.     ;
  273.     ;            outptr[        0] = (DCTELEM) UNFIXH(tmp20 + tmp50);
  274.     ;
  275.     mov    edx, [bp-56]
  276.     sub    edx, [bp-96]
  277.     add    edx, 65536
  278.     sar    edx, 17
  279.     mov    [di+112], dx
  280.     ;
  281.     ;            outptr[DCTSIZE*7] = (DCTELEM) UNFIXH(tmp20 - tmp50);
  282.     ;
  283.     ;
  284.     imul    ebx, 13623
  285.     mov    edx, [bp-92]
  286.     imul    edx, 9102
  287.     sub    ebx, edx
  288.     mov    [bp-108], ebx
  289.     ;
  290.     ;            tmp53 = tmp42 * OSIN_5_16 - tmp43 * OCOS_5_16;
  291.     ;
  292.     mov    edx, [bp-60]
  293.     sub    edx, [bp-108]
  294.     add    edx, 65536
  295.     sar    edx, 17
  296.     mov    [di+96], dx
  297.     ;
  298.     ;            outptr[DCTSIZE*6] = (DCTELEM) UNFIXH(tmp21 - tmp53);
  299.     ;
  300.     mov    edx, [bp-60]
  301.     add    edx, [bp-108]
  302.     add    edx, 65536
  303.     sar    edx, 17
  304.     mov    [di+16], dx
  305.     ;
  306.     ;            outptr[DCTSIZE  ] = (DCTELEM) UNFIXH(tmp21 + tmp53);
  307.     ;
  308.     ;
  309.     mov    edx, [bp-88]
  310.     imul    edx, 9102
  311.     mov    ecx, [bp-92]
  312.     imul    ecx, 13623
  313.     add    edx, ecx
  314.     mov    ecx, edx        ;keep a spare     ;    mov    [bp-104], edx
  315.     ;
  316.     ;            tmp52 = tmp42 * OCOS_5_16 + tmp43 * OSIN_5_16;
  317.     ;
  318.     mov    ebx, [bp-64]        ; a spare copy
  319.     add    edx, ebx
  320.     add    edx, 65536
  321.     sar    edx, 17
  322.     mov    [di+32], dx
  323.     ;
  324.     ;            outptr[DCTSIZE*2] = (DCTELEM) UNFIXH(tmp22 + tmp52);
  325.     ;
  326.     sub    ebx, ecx
  327.     add    ebx, 65536
  328.     sar    ebx, 17
  329.     mov    [di+80], bx
  330.     .286
  331.     ;
  332.     ;            outptr[DCTSIZE*5] = (DCTELEM) UNFIXH(tmp22 - tmp52);
  333.     ;
  334.     ;
  335.     add    si,16
  336.     ;
  337.     ;            inptr += DCTSIZE;        /* advance inptr to next row */
  338.     ;
  339. ;    add    di, 2
  340.     inc    di
  341.     inc    di
  342.     dec    word ptr [bp-4]
  343. @1@122:
  344.     cmp    word ptr [bp-4],0
  345.     jl    @@0
  346.     jmp    @1@74
  347. @@0:
  348.     ;
  349.     ;            outptr++;            /* advance outptr to next column */
  350.     ;         }
  351.     ;         /* end of pass; in case it was pass 1, set up for pass 2 */
  352.     ;
  353.     lea    ax,word ptr [bp-236]
  354.     mov    si,ax
  355.    ;    
  356.    ;         inptr = workspace;
  357.     ;
  358.     mov    di,word ptr [bp+4]
  359.     dec    word ptr [bp-2]
  360. @1@194:
  361.     cmp    word ptr [bp-2],0
  362.     jl    @@1
  363.     jmp    @1@50
  364. @@1:
  365.     ;
  366.     ;         outptr = data;
  367.     ;      }
  368.     ;
  369.     pop    di
  370.     pop    si
  371.     leave
  372.     ret
  373. _j_rev_dct    endp
  374. _TEXT    ends
  375. _DATA    segment word public 'DATA'
  376. s@    label    byte
  377. _DATA    ends
  378. _TEXT    segment byte public 'CODE'
  379. _TEXT    ends
  380.     public    _j_rev_dct
  381. ;    extrn    N_LXMUL@:far
  382. ;    extrn    N_LXLSH@:far
  383. ;    extrn    N_LXRSH@:far
  384.     end
  385.